package com.bjsxt.action;

import java.util.List;

import com.bjsxt.meta.User;
import com.bjsxt.service.UserService;
import com.opensymphony.xwork2.Action;

public class UserAction {
	private User user;
	private List<User> users;
	private UserService service = new UserService();
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}	
	
	public List<User> getUsers() {
		return users;
	}
	public void setUsers(List<User> users) {
		this.users = users;
	}
	public String login(){
		if(service.login(user)){
			return Action.SUCCESS;
		}else{
			return Action.ERROR;
		}
	}
	
	public String list(){
		users = service.list();
		if(users != null){
			return Action.SUCCESS;
		}else{
			return Action.NONE;
		}
	}
	
	public String add(){
		if(service.add(user) > 0){
			return Action.SUCCESS;
		}else{
			return Action.ERROR;
		}
	}
	
	public String del(){
		if(service.del(user) > 0){
			return Action.SUCCESS;
		}else{
			return Action.ERROR;
		}
	}
	
	public String toUpdate(){

		user = service.getUserById(user);
		
		if(user != null){
			return Action.SUCCESS;
		}else{
			return Action.ERROR;
		}
	}
	
	public String update(){
		if(service.update(user) > 0){
			return Action.SUCCESS;
		}else{
			return Action.ERROR;
		}
	}
}
